IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_sp_PageControlAdd]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[cms_sp_PageControlAdd]
GO
create procedure [dbo].[cms_sp_PageControlAdd]
(
@Id int = null output,
@PageId int,
@TemplateRegionId int,
@PageControlContentId int,
@PageControlTypeKey int,
@PageControlOrder int,
@CreatedBy int,
@DateCreated datetime,
@LastUpdatedBy int = null,
@DateLastUpdated datetime = null,
@PageControlViewValue xml = null,
@PageControlModelValue xml = null,
@ModuleId int = null
)
as
declare @IsLatestRevision bit = 1
declare @IsLatestCompletedRevision bit = 0
declare @IsDeleted bit = 0
declare @IsPublished bit = 0
declare @PageControlTypeParameter varchar(50) = 'PageControl'

insert into dbo.PageControls
(
PageId,
TemplateRegionId,
ModuleId,
PageControlContentId,
PageControlTypeKey,
PageControlViewValue,
PageControlModelValue,
PageControlOrder,
CreatedBy,
DateCreated
)
values
(
@PageId,
@TemplateRegionId,
@ModuleId,
@PageControlContentId,
@PageControlTypeKey,
@PageControlViewValue,
@PageControlModelValue,
@PageControlOrder,
@CreatedBy,
@DateCreated
)
set @Id = SCOPE_IDENTITY()
insert into dbo.EntityRevisions
(
EntityId,
PublicEntityId,
EntityTypeParameter,
WorkflowId,
IsLatestRevision,
IsLatestCompletedRevision,
IsDeleted,
IsPublished
)
values
(
@Id,
@Id,
@PageControlTypeParameter,
null,
@IsLatestRevision,
@IsLatestCompletedRevision,
@IsDeleted,
@IsPublished
)
return @Id


GO

